﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NCP.Recruiting.Repository.SqlServer.Data;
using NCP.Recruiting.Domain.Aggregates.Resumes;
using NCP.Recruiting.Repository.SqlServer.UnitOfWork;
using System.Data.Entity;

namespace NCP.Recruiting.Repository.SqlServer.Repositories {
    public class ResumeRepository : Repository<Resume>, IResumeRepository {
        public ResumeRepository(MainBCUnitOfWork unitOfWork)
            : base(unitOfWork) {           
        }

        public override Resume Get(Guid id) {
            var currentUnitOfWork = this.UnitOfWork as MainBCUnitOfWork;
            var set = currentUnitOfWork.CreateSet<Resume>();
            //var set = base.GetSet()
            //    .Include(s=>s.Educations).DefaultIfEmpty()
            //    .Include(s=>s.Works).DefaultIfEmpty()
            //    .Include(s=>s.Skills).DefaultIfEmpty()
            //    .Include(s=>s.Trainings).DefaultIfEmpty()
            //    .Include(s=>s.Certifcations).DefaultIfEmpty();
            //return set.SingleOrDefault(s => s.Id == id);
            return set
                .Include("Educations").DefaultIfEmpty()
                .Include("Works").DefaultIfEmpty()
                .Include("Skills").DefaultIfEmpty()
                .Include("Trainings").DefaultIfEmpty()
                .Include("Certifications").DefaultIfEmpty()
                .Where(r => r.Id == id)
                .SingleOrDefault();
        }

        public IQueryable<Resume> GetResumeByIds(List<Guid> resumeIds)
        {
            return base.GetSet().Where(s => resumeIds.Contains(s.Id));
        }
    }
}
